<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="clr-namespace:PropertyTools.Wpf">
  <ResourceDictionary.MergedDictionaries>
    <ResourceDictionary Source="/PropertyTools.Wpf;component/TreeListBox/Common.xaml" />
  </ResourceDictionary.MergedDictionaries>

  <Style TargetType="{x:Type local:TreeListBox}" BasedOn="{StaticResource {x:Type ListBox}}">
    <Setter Property="SelectionMode" Value="Extended" />
    <Setter Property="AllowDrop" Value="True" />
    <Setter Property="ItemContainerStyle">
      <Setter.Value>
        <Style TargetType="{x:Type local:TreeListBoxItem}">
          <Setter Property="BorderThickness" Value="1" />
          <Setter Property="Background" Value="Transparent" />
          <Setter Property="Padding" Value="{Binding LevelPadding, RelativeSource={RelativeSource Self}}" />
          <Setter Property="Template">
            <Setter.Value>
              <ControlTemplate TargetType="{x:Type local:TreeListBoxItem}">
                <Border x:Name="Bd" CornerRadius="2"
                        BorderThickness="{TemplateBinding BorderThickness}" SnapsToDevicePixels="true">
                  <Border x:Name="Bd2" BorderThickness="1" SnapsToDevicePixels="True"
                          Padding="{TemplateBinding Padding}">
                    <Grid>
                      <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="Auto" />
                        <ColumnDefinition />
                      </Grid.ColumnDefinitions>
                      <ToggleButton x:Name="Expander"
                                    Style="{StaticResource ExpandCollapseToggleStyle}"
                                    IsChecked="{Binding IsExpanded, RelativeSource={RelativeSource TemplatedParent}, Mode=TwoWay}" />
                      <ContentPresenter Grid.Column="1" />
                    </Grid>
                  </Border>
                  <Border.Style>
                    <Style TargetType="{x:Type Border}">
                      <Setter Property="Background" Value="Transparent" />
                      <Style.Triggers>
                        <Trigger Property="IsMouseOver" Value="True">
                          <Setter Property="Background"
                                  Value="{StaticResource MouseOverBackground}" />
                          <Setter Property="BorderBrush"
                                  Value="{StaticResource MouseOverBorder}" />
                        </Trigger>
                      </Style.Triggers>
                    </Style>
                  </Border.Style>
                </Border>
                <ControlTemplate.Triggers>
                  <Trigger Property="HasItems" Value="false">
                    <Setter TargetName="Expander" Property="Visibility" Value="Hidden" />
                  </Trigger>
                  <Trigger Property="IsDropTarget" Value="True">
                    <Setter TargetName="Bd2" Property="Background"
                            Value="{StaticResource MouseOverBackground}" />
                    <Setter TargetName="Bd2" Property="BorderBrush"
                            Value="{StaticResource MouseOverBorder}" />
                  </Trigger>
                  <Trigger Property="IsSelected" Value="true">
                    <Setter TargetName="Bd" Property="Background"
                            Value="{StaticResource SelectedBackground}" />
                    <Setter TargetName="Bd" Property="BorderBrush"
                            Value="{StaticResource SelectedBorder}" />
                    <Setter TargetName="Bd2" Property="BorderBrush"
                            Value="{StaticResource SelectedInnerBorder}" />
                  </Trigger>
                  <Trigger Property="IsEnabled" Value="false">
                    <Setter Property="Foreground"
                            Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}" />
                  </Trigger>
                </ControlTemplate.Triggers>
              </ControlTemplate>
            </Setter.Value>
          </Setter>
        </Style>
      </Setter.Value>
    </Setter>
  </Style>
</ResourceDictionary>